//  Parameter details refer to:https://support.huaweicloud.com/api-natgateway/CreateNatGateway.html
resource "huaweicloud_nat_gateway" "nat" {
  count       = var.is_nat_creat ? 1 : 0
  name        = var.name_suffix != null ? format("%s-%s", var.gateway_name, var.name_suffix) : var.gateway_name
  spec        = var.spec
  vpc_id      = var.vpc_id
  subnet_id   = var.subnet_id
  
  tags = merge(
    { "Name" = var.name_suffix != null ? format("%s-%s", var.gateway_name, var.name_suffix) : var.gateway_name},
    var.nat_tags)
}

resource "huaweicloud_nat_snat_rule" "snat" {
  count = var.is_nat_creat ? 1 : 0
  nat_gateway_id = huaweicloud_nat_gateway.nat[0].id
  floating_ip_id = var.publicip_id
  subnet_id      = var.subnet_id
}
